package com.xinruke.hostels.reservation.user.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.reservation.user.interfaces.dto.*;
import com.xinruke.hostels.reservation.user.service.MemberService;
import com.xinruke.hostels.reservation.user.service.PersonalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author ChenXiangpeng
 * @ClassName MemberInnerAPIController
 * @date：2019/7/26
 * @version: V1.0.0
 * @description：
 */
@RestController
@RequestMapping("/memberInnerAPI")
@Api(tags = "会员管理")
public class MemberInnerAPIController extends BaseController {
    @Autowired
    private MemberService memberService;
    @Autowired
    private PersonalService personalService;

    /**
     * 会员列表查询
     *
     * @param memberListQueryDTO
     * @return
     */
    @PostMapping(value = "/memberList")
    @ApiOperation("查询会员列表")
    public ResultVO<RowsDataVO<MemberDetailQuertResultDTO>> memberList(@Valid @RequestBody MemberListQueryDTO memberListQueryDTO) {
        return memberService.getMemberList(memberListQueryDTO);
    }


    /**
     * 新增会员
     *
     * @param memberAddDTO
     * @return
     */
    @PostMapping(value = "/add")
    @ApiOperation("新增会员")
    public ResultVO addMember(@Valid @RequestBody MemberAddDTO memberAddDTO) {
        return memberService.userAdd(memberAddDTO);
    }

    /**
     * 根据ID查询会员的详细信息
     *
     * @param memberDetailQueryByIdDTO
     * @return
     * @Author: ChenXiangpeng
     * @Date: 2019/7/26 15:59
     */
    @PostMapping("/detail")
    @ApiOperation("会员个人信息")
    public ResultVO<MemberDetailQuertResultDTO> detailById(@Valid @RequestBody MemberDetailQueryByIdDTO memberDetailQueryByIdDTO) {
        return memberService.detailById(memberDetailQueryByIdDTO);
    }

    /**
     * 查看常用联系人
     */
    @PostMapping("/contacts")
    @ApiOperation("查看当前用户的常用联系人列表")
    public ResultVO<RowsDataVO<ContactsInfo>> contactsList(@Valid @RequestBody ContactsListQueryDTO contactsListQueryDto) {
        ResultVO<RowsDataVO<ContactsInfo>> resultVO = ResultVO.fail();
        RowsDataVO<ContactsInfo> data = personalService.contactsList(contactsListQueryDto);
        resultVO.setCode(ResultVO.SUCCESS);
        resultVO.setMessage("操作成功");
        resultVO.setData(data);
        return resultVO;
    }

    /**
     * 查看常用联系人详情
     */
    @PostMapping("/contacts/detail")
    @ApiOperation("详情")
    public ResultVO<ContactsDetailResultDto> contactDetail(@Valid @RequestBody ContactsDetailQueryDTO queryDTO) {
        return personalService.contactDetail(queryDTO);
    }
}
